package com.zygk.locationtool.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import com.zygk.library.base.BaseActivity;
import com.zygk.locationtool.R;
import com.zygk.locationtool.fragment.StationListInnerFragment;

/**
 * Created by Wikison on 2018/12/8.
 * 站点列表
 */
public class StationListActivity extends BaseActivity {
  @BindView(R.id.ll_back) LinearLayout llBack;
  @BindView(R.id.iv_right) ImageView ivRight;
  @BindView(R.id.ll_right) LinearLayout llRight;
  @BindView(R.id.lh_tv_title) TextView lhTvTitle;
  @BindView(R.id.tab) TabLayout tab;
  @BindView(R.id.vp) ViewPager vp;

  private MyFragmentAdapter mAdapter;

  @Override protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ButterKnife.bind(this);
  }

  @Override public void setContentView() {
    setContentView(R.layout.activity_station_list);
  }

  @Override public void init() {
    initData();
    initView();
    initListener();
  }

  private void initData() {
    mAdapter = new MyFragmentAdapter(getSupportFragmentManager());
    vp.setAdapter(mAdapter);
    vp.setOffscreenPageLimit(2);
    tab.setupWithViewPager(vp);
  }

  private void initView() {
    lhTvTitle.setText("GPS定位助手");
    llRight.setVisibility(View.VISIBLE);
    ivRight.setImageResource(R.mipmap.icon_head_search);
  }

  private void initListener() {
  }

  private class MyFragmentAdapter extends FragmentPagerAdapter {
    private String[] titles = new String[] { "未设置", "已设置" };
    StationListInnerFragment innerFragment;

    public MyFragmentAdapter(FragmentManager fm) {
      super(fm);
    }

    @Override public Fragment getItem(int position) {
      innerFragment = new StationListInnerFragment();
      Bundle bundle = new Bundle();
      bundle.putSerializable("page_position", position);
      innerFragment.setArguments(bundle);
      return innerFragment;
    }

    @Override public int getCount() {
      return titles.length;
    }

    @Override public CharSequence getPageTitle(int position) {
      return titles[position];
    }
  }

  @OnClick({ R.id.ll_back, R.id.ll_right }) public void onViewClicked(View view) {
    switch (view.getId()) {
      case R.id.ll_back:
        finish();
        break;
      case R.id.ll_right:
        startActivity(new Intent(mContext, StationSearchActivity.class));
        break;
    }
  }
}
